package org.example.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.entity.Dianpu;
import org.example.entity.Gzdiapu;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface Dianpumapper {
    /**
     * 店铺查询
     * @param username
     */
    @Select("select * from dianpu where username=#{username}")
    Dianpu dianpucx(String username);

    /**
     * 店铺新增
     * @param shopName
     * @param shopDescription
     * @param s
     * @param s1
     * @param username
     */
    @Insert("INSERT INTO dianpu (shop_name,shop_description,avatar,background,username)" +
            "VALUES\n" +
            "(#{shopName},#{shopDescription},#{s},#{s1},#{username})")
    void dianpuxz(String shopName, String shopDescription, String s, String s1, String username);

    /**
     *店铺修改
     * @param shopName
     * @param shopDescription
     * @param s
     * @param s1
     * @param username
     */
    @Insert("UPDATE dianpu\n" +
            "SET shop_name=#{shopName}, shop_description =#{shopDescription},avatar=#{s}," +
            "background=#{s1}\n" +
            "WHERE username=#{username}")
    void dianpuxg(String shopName, String shopDescription, String s, String s1, String username);

    /**
     * 店铺关注查询
     * @param dianpuusername
     * @param yonghuusername
     * @return
     */
    @Select("select id from dianpugz where dianpu_username=#{dianpuusername} and yonghu_username=#{yonghuusername}")
    Object gzcx(String dianpuusername, String yonghuusername);

    /**
     * 店铺关注删除
     * @param dianpuusername
     * @param yonghuusername
     */
    @Delete("delete from dianpugz\n" +
            "WHERE dianpu_username=#{dianpuusername} and yonghu_username=#{yonghuusername}")
    void gzsc(String dianpuusername, String yonghuusername);


    /**
     * 店铺关注新增
     *
     * @param dianpuusername
     * @param yonghuusername
     * @param time
     */
    @Insert("INSERT INTO dianpugz (dianpu_username,yonghu_username,gztime)" +
            "VALUES\n" +
            "(#{dianpuusername},#{yonghuusername},#{time})")
    void gzxz(String dianpuusername, String yonghuusername, LocalDateTime time);

    /**
     *
     * @param yonghuusername
     * @return
     */
    @Select("select dianpu_username,gztime from dianpugz where yonghu_username=#{yonghuusername}")
    Gzdiapu[] gzdianpucx(String yonghuusername);

    /**
     * 店铺查询总
     * @param souso
     * @return
     */
    @Select("select * from dianpu where shop_name like CONCAT('%', #{souso}, '%')")
    List<Dianpu> dianpucxs(String souso);

    /**
     * 删除
     * @param
     * @param
     */
    @Delete("delete from dianpugz\n" +
            "WHERE yonghu_username=#{username}")
    void gzzx(String username);

    /**
     * 删除
     * @param
     * @param
     */
    @Delete("delete from dianpu\n" +
            "WHERE username=#{username}")
    void zx(String username);
    @Delete("delete from dianpugz\n" +
            "WHERE dianpu_username=#{username}")
    void zxgz(String username);
}
